const state = {
  history: [
    {
      name: 'index-welcome',
      path: '/index/welcome',
      title: '首页',
    },
  ],
}

const mutations = {
  setHistory(state, { name, path, title }) {
    //重复判断
    if (state.history.some((item) => item.name === name)) return
    state.history.push({
      name,
      path,
      title,
    })
  },
  removeHistory(state, { name, type }) {
    //type -> current:当前/other:其他/all:全部
    state.history = state.history.filter((item) => {
      //保留首页
      if (item.name === 'index-welcome') return true
      //移出全部
      if (type === 'all') return false
      //移除当前
      if (type === 'current') return item.name !== name
      //移除其他
      if (type === 'other') return item.name === name
    })
  },
}

const actions = {}

const tabs = {
  namespaced: true,
  state,
  mutations,
  actions,
}

export default tabs
